/**
 * @author Nicolas Latorre(nicolas.latorre@usi.ch)
 */
package ch.usi.inf.pf2.file.interaction;

import java.util.ArrayList;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Scanner;

import ch.usi.inf.pf2.circuit.Component;

public final class InstructionWriter {
	
	private String fileLocation;
	private ArrayList<Component> circuit;
	
	public InstructionWriter(final String location, final ArrayList<Component> circuit) {
		fileLocation = location;
		this.circuit = circuit;
		writeInstruction(fileLocation);
	}
	
	/**
	 * This method write in a file the instructions contained in the ArrayList instructions.
	 * @param fileLocation, is a string that contains the path of the file.
	 */
	public void writeInstruction(final String fileLocation) {
		FileOutputStream fos = null;
		ObjectOutputStream out = null;
		
		try {
			fos = new FileOutputStream(fileLocation);
			out = new ObjectOutputStream(fos);
			out.writeObject(circuit);
			out.close();
		}
		catch(IOException e) {
			System.err.println("Failed to save to " + fileLocation);
		}
	}
//	//This variable store the location where the user want to save the file.
//	private  String fileLocation;
//	//This ArrayList contain the instruction that will be saved.
//	private final ArrayList<String> instructions;
//	
//	public InstructionWriter() {
//		fileLocation = null;
//		instructions = new ArrayList<String>();
//		//putInstruction();
//		//writeInstruction(fileLocation);
//	}
//	
//	/**
//	 * This method fill the ArrayList instruction, with some instruction.
//	 */
//	public void putInstruction() {
//		instructions.add("Output output = new Output()");
//		instructions.add("InputPin inputPin = new InputPinOutput(output)");
//		instructions.add("Wire wire1 = new Wire(inputPin");
//		instructions.add("OutputPin outputPin = new OutputPin(wire1)");
//		instructions.add("Gate notGate = new Gate(outputPin)");
//	}
//	
//	/**
//	 * This method write in a file the instructions contained in the ArrayList instructions.
//	 * @param fileLocation, is a string that contains the path of the file.
//	 */
//	public void writeInstruction(final String fileLocation) {
//		try {
//			FileWriter writer = new FileWriter(fileLocation);
//			for(String instruction : instructions) {
//				writer.write(instruction);
//				writer.write('\n');
//			}
//			writer.close();
//		}
//		catch(IOException e) {
//			System.err.println("Failed to save to " + fileLocation);
//		}
//	}
//	
//	/**
//	 * This method ask to the user where he want to save the file.
//	 * @return inputLine, this string contains the path of the file.
//	 */
//	public void chooseLocationToSaveTheFile() {
//		System.out.println("Where do you want to save the file?");
//		Scanner location = new Scanner(System.in);
//		String inputLine = location.nextLine();
//		fileLocation = inputLine;
//	}
//	
//	public String getLocation() {
//		return fileLocation;
//	}

}
